package org.ywf.framework.proxy;

import org.ywf.common.entity.RequestData;
import org.ywf.common.entity.ResponseData;
import org.ywf.web.entity.User;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public abstract class ProxyInvocationHandler implements InvocationHandler {

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //Object走原生方法,equals,hashCode
        if (Object.class.equals(method.getDeclaringClass())){
            return method.invoke(this, args);
        }
        //其他方法走本地代理
        RequestData<?> arg = new RequestData();
        if (args!=null && args.length!=0){
            arg = (RequestData<?>) args[0];
        }
        return this.handler(method,arg);
    }

    protected abstract ResponseData<?> handler(Method method, RequestData<?> request);


}
